/*
 * File:    Defines.h
 * Project:	HobbyPilotFirmware (HPF)
 * Author:  Wouter van Verre
 *
 * Created on February 8, 2011, 9:39 PM
 */

#ifndef __DEFINES_H
#define __DEFINES_H

/** Includes **/

/** Defines **/
#define false 			0
#define true 			1

#define FCY 			14740000ULL
#define F_IMU_LOOP 		100.0

#define FRACT_214_10	0b0100000000000000;

/** Typedefines **/

/** Structures **/
typedef struct 
{
	unsigned gotOffsets		:1;
	unsigned readingADC		:1;
	unsigned readADC		:1;
	unsigned				:5;
} structCPUStatus;


/** Unions **/

/** Function Definitions **/
extern void toggleActivityLED(void);
extern void toggleYellowLED(void);
extern void toggleOrangeLED(void);
extern void turnOffYellowLED(void);
extern void turnOffOrangeLED(void);
extern void turnOnYellowLED(void);
extern void turnOnOrangeLED(void);
extern void writeToUART1(void);
extern void readFromUART1(void);

extern void readSensorChannels(void);
extern void UpdateRotationMatrix(void);			
extern void RenormalizeRotationMatrix(void);	
extern void CancelDrift(void);	

extern void m3x3_MatrixMultiply(float * Mat1, float * Mat2, float * Dest);
extern void m3x3_MatrixSetRow(float * Matrix, float * Vector);
extern void v3_VectorAdd(float * Vect1, float * Vect2, float * Dest);
extern void v3_VectorScale(float * Vect, float S, float * Dest);
extern void v3_VectorDotProduct(float * Vect1, float * Vect2, float * Dest);
extern void v3_VectorCrossProduct(float * Vect1, float * Vect2, float * Dest);
extern void v3_GetRowAsVector(float * Matrix, float * Dest);

extern inline void EnterInterrupt(void);
extern inline void ExitInterrupt(void);

/** Variables **/
extern structCPUStatus CPUStatus;
extern int initCounter;

extern uint16 cpuLoadCycles;
extern uint8 cpuLoad;
extern uint8 cpuLoadMax;
extern uint16 cpuStackUse;
extern uint16 cpuStackUseMax;

extern float v3_GyroCorrP[3], v3_GyroCorrI[3];
extern float KpRollPitch, KiRollPitch, GyroGain, AccelGain;
extern float m3x3_Rotation[9];

extern float dt;

#endif
